package com.M10.BE.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.M10.BE.R;
import com.M10.BE.inventory.CheckedInveDetailActivity;
import com.fn.useries.model.Inventory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/8/2.
 */

public class InveCheckListAdapter extends RecyclerView.Adapter<InveCheckListAdapter.MasonryView> {
    private List<Inventory> inventories;
    private Context ctx;

    public InveCheckListAdapter(ArrayList<Inventory> inventories, Context context) {
        this.inventories = inventories;
        ctx = context;
    }

    @Override
    public InveCheckListAdapter.MasonryView onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_inventory_checked, parent, false);
        return new InveCheckListAdapter.MasonryView(view);
    }

    @Override
    public void onBindViewHolder(InveCheckListAdapter.MasonryView holder, final int position) {
        holder.tv_orderNo.setText(inventories.get(position).getOrderNO());
        holder.tv_dept.setText(inventories.get(position).getOrgName());
        holder.tv_checkresult.setText(inventories.get(position).getStatus() ? "盘亏" : "无盈亏");
        holder.tv_time.setText(inventories.get(position).getJudgeDate());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ctx, CheckedInveDetailActivity.class);
                intent.putExtra("inventoryId", inventories.get(position).getId());
                ctx.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return inventories.size();
    }

    public static class MasonryView extends RecyclerView.ViewHolder {
        TextView tv_orderNo;
        TextView tv_dept;
        TextView tv_checkresult;
        TextView tv_time;

        public MasonryView(View itemView) {
            super(itemView);
            tv_orderNo = (TextView) itemView.findViewById(R.id.inve_oderno);
            tv_dept = (TextView) itemView.findViewById(R.id.inve_dept);
            tv_checkresult = (TextView) itemView.findViewById(R.id.inve_check_result);
            tv_time = (TextView) itemView.findViewById(R.id.inve_time);
        }

    }
}
